let head = [1, 2, 3, 4, 5]
let list = new ListNode(head[0])
let num = list
for (let i = 1; i < head.length; i++) {
    num.next = new ListNode(head[i])
    num = num.next
}
function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
// console.log(list);

var middleNode = function (head) {
    let num = head
    let arr = []
    while (num) {
        arr.push(num)
        num = num.next
    }
    let n = arr.length
    return arr[Math.floor(n / 2)]
};
console.log(middleNode(list));
